#!/usr/bin/env python
"""
Simple program to run multiple worker processes.
"""
import os
import subprocess

from netlogger.nllog import OptionParser, get_logger

def main():
    usage = "%prog -H HOST -n NUM"
    desc = ' '.join(__doc__.split())
    parser = OptionParser(usage=usage, description=desc)
    parser.add_option('-n', '--num', metavar='NUM',
                      action='store', type='int', dest='num', default=1,
                      help="Start NUM of worker processes")
    parser.add_option('-H', '--host', metavar='HOST',
                      action='store', dest='host', default="localhost",
                      help="Host for workers to contact")
    options, args = parser.parse_args()
    
    procs = []
    
    for i in range(1, options.num+1):
        CMD = '%s/amqp_mbench.py w -H %s -w %s -s 3' % (os.getcwd(), options.host, i)
        p = subprocess.Popen(CMD.split())
        procs.append(p)
        print 'launched worker:', i
        
    print 'waiting for workers...'
    for p in procs:
        p.wait()
    print 'Done'
    pass

if __name__ == '__main__':
    main()